package com.songlanyun.modules.category.controller.admin;

import java.util.List;
import java.util.Map;

import com.songlanyun.common.annotation.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.category.entity.SystemProductCategoryEntity;
import com.songlanyun.modules.category.service.SystemProductCategoryService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.user.controller.AbstractController;


/**
 * 平台的商品分类表的控制层 api
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-02 15:58:00
 */
@RestController
@RequestMapping("admin/category")
public class SystemProductCategoryAdminController extends  AbstractController{
    @Autowired
    private SystemProductCategoryService systemProductCategoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("system:category:list")
    public R page(@RequestParam Map<String, Object> params){
        PageUtils page = systemProductCategoryService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 所有分类
     */
    @RequestMapping("/all")
    //@RequiresPermissions("system:category:all")
    public R all(){
        List<Map<String, Object>> objs = systemProductCategoryService.getAllCategory();
        return R.ok().put("list", objs);
    }


    /**
     * 所有分类
     */
    @RequestMapping("/first")
    //@RequiresPermissions("system:category:all")
    public R first(){
        List<SystemProductCategoryEntity> objs = systemProductCategoryService.getFirstCategory();
        return R.ok().put("list", objs);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("system:category:info")
    public R info(@PathVariable("id") Long id){
        SystemProductCategoryEntity category = systemProductCategoryService.getById(id);
        return R.ok().put("data", category);
    }

    /**
     * 保存
     */
    @SysLog("保存平台的商品分类")
    @PostMapping("/create")
    //@RequiresPermissions("system:category:save")
    public R create(@RequestBody SystemProductCategoryEntity category){
        SystemProductCategoryEntity obj =systemProductCategoryService.create(category);
        return R.ok().put("data", obj);
    }

    /**
     * 修改
     */
    @SysLog("修改平台的商品分类")
    @PutMapping ("/update")
    //@RequiresPermissions("system:category:update")
    public R update(@RequestBody SystemProductCategoryEntity systemProductDepartment){
        SystemProductCategoryEntity obj = systemProductCategoryService.modify(systemProductDepartment);
        return R.ok().put("data", obj);
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("system:category:delete")
    public R delete(@PathVariable("id") Long id){
        systemProductCategoryService.remove(id);
        return R.ok();
    }

}

